package com.meituan.catering.management.order.biz.model.converter;

import com.meituan.catering.management.order.api.http.model.request.PlaceCateringOrderHttpRequest;
import com.meituan.catering.management.order.biz.model.request.PlaceCateringOrderBizRequest;

import java.util.LinkedList;
import java.util.List;

/**
 * @author Believe
 * Date 2022/5/30 9:43
 */
public class PlaceCateringOrderBizRequestConverter {
    public static PlaceCateringOrderBizRequest toPlaceCateringOrderBizRequest(PlaceCateringOrderHttpRequest placeCateringOrderHttpRequest){
        PlaceCateringOrderBizRequest placeCateringOrderBizRequest = new PlaceCateringOrderBizRequest();
        placeCateringOrderBizRequest.setShopBusinessNo(placeCateringOrderHttpRequest.getShopBusinessNo());
        placeCateringOrderBizRequest.setTableNo(placeCateringOrderHttpRequest.getTableNo());
        placeCateringOrderBizRequest.setCustomerCount(placeCateringOrderHttpRequest.getCustomerCount());
        placeCateringOrderBizRequest.setTotalPrice(placeCateringOrderHttpRequest.getTotalPrice());
        placeCateringOrderBizRequest.setComment(placeCateringOrderHttpRequest.getComment());
        placeCateringOrderBizRequest.setItems(toItem(placeCateringOrderHttpRequest.getItems()));
        return placeCateringOrderBizRequest;
    }

    public static List<PlaceCateringOrderBizRequest.Item> toItem(List<PlaceCateringOrderHttpRequest.Item> itemList){
        List<PlaceCateringOrderBizRequest.Item> list = new LinkedList<>();
        for (PlaceCateringOrderHttpRequest.Item item : itemList) {
            PlaceCateringOrderBizRequest.Item bizItem = new PlaceCateringOrderBizRequest.Item();
            bizItem.setSeqNo(item.getSeqNo());
            bizItem.setQuantity(item.getQuantity());
            bizItem.setProductId(item.getProductId());
            bizItem.setProductMethodId(item.getProductMethodId());
            bizItem.setAccessories(toAccessory(item.getAccessories()));
            list.add(bizItem);
        }
        return list;
    }

    public static List<PlaceCateringOrderBizRequest.Item.Accessory> toAccessory(List<PlaceCateringOrderHttpRequest.Item.Accessory> accessoryList){
        List<PlaceCateringOrderBizRequest.Item.Accessory> bizAccessoryList = new LinkedList<>();
        for (PlaceCateringOrderHttpRequest.Item.Accessory accessory : accessoryList) {
            PlaceCateringOrderBizRequest.Item.Accessory acc = new PlaceCateringOrderBizRequest.Item.Accessory();
            acc.setSeqNo(accessory.getSeqNo());
            acc.setQuantity(accessory.getQuantity());
            acc.setProductAccessoryId(accessory.getProductAccessoryId());
            bizAccessoryList.add(acc);
        }
        return bizAccessoryList;
    }
}
